package com.easyaop.asm.bytecode;

import com.easyaop.commons.utils.IOUtils;
import com.easyaop.core.Inst;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.objectweb.asm.Type;

import java.lang.reflect.Method;

@AllArgsConstructor
public class DefaultQuery
{

    @Getter
    private byte[] bytes;
    @Getter
    private String className;
    @Getter
    private String method;
    @Getter
    private String descriptor;

    @Getter
    private byte[] aopBytes;
    @Getter
    private Integer joinPoint;

    public DefaultQuery(Method _method, Class around) {

        this.bytes = IOUtils.from(_method.getDeclaringClass());
        this.method = _method.getName();
        this.descriptor = Type.getMethodDescriptor(_method);
        this.className=_method.getDeclaringClass().getName();
        this.aopBytes = IOUtils.from(around);
        this.joinPoint = Context.index(_method);
    }

    public DefaultQuery(ClassLoader loader,String className,byte[] bytes,String method,String desc,Class around) {
        this.bytes = bytes;
        this.method=method;
        this.descriptor=desc;
        this.aopBytes=IOUtils.from(around);
//        this.aopBytes= Inst.getBytes(around);
        this.className=className;
        this.joinPoint=Context.index(loader,className,method,desc);

    }
}
